var _n80;
var cc__extends = __extends;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$gameConfig1 = require("gameConfig1");
var a = cc__importDefault($1$gameConfig1);
var $zqcc_OverallSystem = require("zqcc_OverallSystem");
var $miniGameApiBase = require("miniGameApiBase");
var l = window.tt;
var def_ttApi = function (t) {
  function _ctor() {
    var e = null !== t && t.apply(this, arguments) || this;
    e.m_AppId = "";
    e.m_Secret = "";
    e.m_VideoAdIdIndex = 0;
    e.m_VideoAdIdList = ["67qgnd2jhao77ju50q"];
    e.m_BannerAdIdIndex = 0;
    e.m_BannerAdId = [];
    e.m_InsertAdIdIndex = 0;
    e.m_InsertAdId = [];
    e.m_videoAd = undefined;
    e.m_BannerAd = undefined;
    e.m_gameRecorder = null;
    e.m_gameRecordDate = 0;
    e.m_gameRecordUrl = undefined;
    return e;
  }
  cc__extends(_ctor, t);
  _ctor.prototype.validAppId = function () {};
  _ctor.prototype.ready = function () {
    cc.log("tt-api-ready");
    this.m_gameRecorder = l.getGameRecorderManager();
    var t = l.getUpdateManager();
    t.onUpdateReady(function () {
      l.showModal({
        title: "更新提示",
        content: "新版本已经准备好，是否重启小游戏？",
        success(e) {
          e.confirm && t.applyUpdate();
        }
      });
    });
    t.onUpdateFailed(function (t) {
      console.log("版本下载失败原因", t);
      l.showToast({
        title: "新版本下载失败，请稍后再试",
        icon: "none"
      });
    });
  };
  _ctor.prototype.getUserInfo = function (t) {
    l.getUserInfo(t);
  };
  _ctor.prototype.showToast = function (t) {
    l.showToast(t);
  };
  _ctor.prototype.showLoading = function (t) {
    l.showLoading(t);
  };
  _ctor.prototype.hideLoading = function () {
    l.hideLoading();
  };
  _ctor.prototype.showModal = function (t) {
    l.showModal(t);
  };
  _ctor.prototype.authorize = function (t) {
    t.success && t.success();
  };
  _ctor.prototype.login = function (t) {
    l.login(t);
  };
  _ctor.prototype.getVideoAdId = function () {
    var t = this.m_VideoAdIdList[this.m_VideoAdIdIndex];
    this.m_VideoAdIdIndex++;
    this.m_VideoAdIdIndex >= this.m_VideoAdIdList.length && (this.m_VideoAdIdIndex = 0);
    return t;
  };
  _ctor.prototype.loadAndShowVideoAd = function (t, e, o, n, i) {
    var r = this;
    undefined === i && (i = "game_use_prop");
    if (window["GM-mode"]) {
      t();
    } else {
      this.showLoading({
        title: "请求中",
        mask: true
      });
      var a = this.getVideoAdId();
      cc.log("tt 视频广告", a, n);
      var c = l.createRewardedVideoAd({
        adUnitId: a
      });
      var u = function u(a) {
        c.offClose(u);
        cc.log("tt 视频广告关闭", a);
        if (a && a.isEnded) {
          t();
          r.reportAnalytics(i, n);
        } else {
          e("视频中途退出");
        }
        r.hideLoading();
        var l = !(!a || !a.isEnded);
        r.reportAd(l);
        o && o();
        $zqcc_OverallSystem.mgrs().soundMgr.isPlayMusic && $zqcc_OverallSystem.mgrs().soundMgr.playMusic($zqcc_OverallSystem.mgrs().soundMgr.shangyige);
      };
      cc.log("展示一次");
      c.load().then(function () {
        c.show().then(function () {
          r.hideLoading();
          c.onClose(u);
        }).catch(function () {
          cc.log("重试一次");
          c.load().then(function () {
            c.show().then(function () {
              r.hideLoading();
              c.onClose(u);
            }).catch(function () {
              e && e("视频展示异常");
              r.showToast({
                title: "视频展示异常",
                duration: 2e3
              });
              r.hideLoading();
              o && o();
            });
          }).catch(function () {
            e && e("视频拉取异常02");
            o && o();
            r.hideLoading();
            r.showToast({
              title: "视频拉取异常",
              duration: 2e3
            });
          });
        });
      }).catch(function () {
        e && e("视频拉取异常01");
        o && o();
        r.hideLoading();
        r.showToast({
          title: "视频拉取异常",
          duration: 1e3
        });
      });
    }
  };
  _ctor.prototype.reportAd = function (t) {
    var e = {
      complete: t
    };
    console.log("reportAd", e);
    seeg.reportAd(e);
  };
  _ctor.prototype.FullScreenVideoAd = function () {};
  _ctor.prototype.getInsertAdId = function () {
    var t = this.m_InsertAdId[this.m_InsertAdIdIndex];
    this.m_InsertAdIdIndex++;
    this.m_InsertAdIdIndex >= this.m_InsertAdId.length && (this.m_InsertAdIdIndex = 0);
    return t;
  };
  _ctor.prototype.showInsertAd = function (t, e) {
    cc.log("加抖音 插屏 广告");
    var o = this.getInsertAdId();
    var n = l.createInterstitialAd({
      adUnitId: o
    });
    n.load();
    n.onLoad(function () {
      console.warn("插屏广告 加载完成");
      n.show().catch(function (t) {
        console.warn("插屏广告 显示失败 :" + JSON.stringify(t));
        n.destroy();
        n = null;
        e && e();
      });
    });
    n.onError(function (t) {
      console.warn("插屏广告 加载失败" + JSON.stringify(t));
      n.destroy();
      n = null;
      e && e();
    });
    n.onClose(function () {
      console.warn("插屏广告 关闭");
      if (null != n) {
        n.destroy();
        n = null;
      }
      t && t();
    });
  };
  _ctor.prototype.getBannerAdId = function () {
    var t = this.m_BannerAdId[this.m_BannerAdIdIndex];
    this.m_BannerAdIdIndex++;
    this.m_BannerAdIdIndex >= this.m_BannerAdId.length && (this.m_BannerAdIdIndex = 0);
    return t;
  };
  _ctor.prototype.showBannerAD = function () {};
  _ctor.prototype.hideBanner = function () {};
  _ctor.prototype.recordedGameScreenStart = function (t, e) {
    var o = this;
    this.m_gameRecordDate = Date.now();
    this.m_gameRecordUrl = null;
    this.m_gameRecorder.onStart(function (t) {
      cc.log("tt 录屏开始", t);
      e && e(t);
    });
    this.m_gameRecorder.onStop(function (t) {
      cc.log("tt 录屏结束", t.videoPath);
      o.m_gameRecordUrl = t.videoPath;
    });
    this.m_gameRecorder.start(t);
  };
  _ctor.prototype.recordedGameScreenStop = function () {
    return !(Date.now() - this.m_gameRecordDate < 3500 || (this.m_gameRecorder.stop(), 0));
  };
  _ctor.prototype.shareRecordedGameScreen = function (t, e) {
    if (this.m_gameRecordUrl) {
      l.shareAppMessage({
        channel: "video",
        title: a.default.GAME_NAME,
        desc: a.default.GAME_VIDEO_SHARE_DESC,
        extra: {
          hashtag_list: [a.default.GAME_NAME],
          videoPath: this.m_gameRecordUrl,
          videoTopics: [a.default.GAME_NAME],
          video_title: a.default.GAME_VIDEO_SHARE_TITLE,
          withVideoId: true,
          defaultBgm: "https://v.douyin.com/JmcxWo8/"
        },
        success(e) {
          cc.log("tt 分享视频成功");
          cc.log(e.videoId);
          cc.log(e.shareWithShareBgmStatus);
          cc.log("分享视频成功 4");
          t && t();
        },
        fail(t) {
          cc.log("tt 分享视频失败", t);
          e && e(t);
        }
      });
    } else {
      e && e(null);
      cc.log("tt 分享视频为空");
    }
  };
  _ctor.prototype.isHaveRecordedGameScreen = function () {
    return true;
  };
  _ctor.prototype.reportAnalytics = function (t, e) {
    var o = window.SEEG_USER_INFO;
    var n = "";
    if (o) {
      if (11 === o.abTest) {
        n = "tt_B_";
      } else {
        10 === o.abTest && (n = "tt_A_");
      }
    }
    var i = n + t;
    e.level && (i = i + "_" + e.level);
    if (!(e.level && e.level > 40)) {
      console.log("埋点");
      console.log(i);
      console.log(e);
      seeg.onEvent(i, e);
    }
  };
  _ctor.prototype.vibrateShort = function (t, e) {
    undefined === t && (t = true);
    undefined === e && (e = "medium");
    if ($zqcc_OverallSystem.mgrs().soundMgr.isVibration) {
      cc.log("震动" + e);
      if (cc.sys.platform != cc.sys.VIVO_GAME && cc.sys.platform != cc.sys.OPPO_GAME && window.wx && window.wx.vibrateShort) {
        if (t) {
          window.wx.vibrateLong({
            type: e,
            style: e
          });
        } else {
          window.wx.vibrateShort({
            type: e,
            style: e
          });
        }
      }
    }
  };
  _ctor.prototype.shareAppMessage = function (t, e, o) {
    undefined === t && (t = "");
    undefined === e && (e = "");
    undefined === o && (o = null);
    l.shareAppMessage({
      title: t,
      desc: e,
      imageUrl: "",
      query: "",
      success() {
        console.log("分享成功");
      },
      fail() {
        console.log("分享失败");
      }
    });
  };
  return _ctor;
}($miniGameApiBase.MiniGameApiBase);
exports.default = def_ttApi;